<?php 
$currentPage = $_SERVER["PHP_SELF"];

$maxRows_rs_cateory = $GLOBALS['NUMTOVIEW'];
$pgnum = 0;
if (isset($_GET['pgnum'])) {
  $pgnum = $_GET['pgnum'];
}
$itemid =$_GET['itemid'];
$startRow_rs_cateory = $pgnum * $maxRows_rs_cateory;

$rs_cateory =getContentCatList($itemid, $startRow_rs_cateory,"NO");
$row_rs_cateory = mysql_fetch_assoc($rs_cateory);

if (isset($_GET['ttnum'])) {
  $ttnum = $_GET['ttnum'];
} else {
  $all_rs_cateory = getContentCatList($itemid,$startRow_rs_cateory,"YES");
  $ttnum = mysql_num_rows($all_rs_cateory);
}
$totalPages_rs_cateory = ceil($ttnum/$maxRows_rs_cateory)-1;

$queryString_rs_cateory = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pgnum") == false && 
        stristr($param, "ttnum") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_rs_cateory = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_rs_cateory = sprintf("&ttnum=%d%s", $ttnum, $queryString_rs_cateory);
?>

<form id="frmcontentview" name="frmcontentview" method="post" action="">
  <table border="0">
    <tr>
      <td><?php if ($pgnum > 0) { // Show if not first page ?>
          <a href="<?php printf("%s?pgnum=%d%s", $currentPage, 0, $queryString_rs_cateory); ?>">First</a>
        <?php } // Show if not first page ?></td>
      <td><?php if ($pgnum > 0) { // Show if not first page ?>
          <a href="<?php printf("%s?pgnum=%d%s", $currentPage, max(0, $pgnum - 1), $queryString_rs_cateory); ?>">Previous</a>
        <?php } // Show if not first page ?></td>
      <td><?php if ($pgnum < $totalPages_rs_cateory) { // Show if not last page ?>
          <a href="<?php printf("%s?pgnum=%d%s", $currentPage, min($totalPages_rs_cateory, $pgnum + 1), $queryString_rs_cateory); ?>">Next</a>
        <?php } // Show if not last page ?></td>
      <td><?php if ($pgnum < $totalPages_rs_cateory) { // Show if not last page ?>
          <a href="<?php printf("%s?pgnum=%d%s", $currentPage, $totalPages_rs_cateory, $queryString_rs_cateory); ?>">Last</a>
          <?php } // Show if not last page ?></td>
      <td><?php echo ($startRow_rs_cateory + 1) ?> - <?php echo min($startRow_rs_cateory + $maxRows_rs_cateory, $ttnum) ?> / <?php echo $ttnum ?></td>
      <td><label>
        <input type="submit" name="button" id="button" value="Approve" onclick="document.getElementById('frmaction').value='approve'" />
      </label>
        <input type="submit" name="button2" id="button2" value="Delete" onclick="document.getElementById('frmaction').value='delete';return confirm('Do YOU really want to delete this Item as it might delete other sub Item');" />
        <input type="hidden" name="frmaction" id="frmaction" />
        <input name="frmCont" type="hidden" id="frmCont" value="content" />
      <input name="chkprefix" type="hidden" id="chkprefix" value="delchk" /></td>
    </tr>
  </table>
  <table width="100%" border="0" cellpadding="0" cellspacing="0" id="datatable">
    <tr>
      <th>contentid</th>
      <th>ptitle</th>
      <th>categoryid</th>
      <th>datecreated</th>
      <th>&nbsp;</th>
      <th>ispublished
        <input type="checkbox" name="delchk_0" id="delchk_0" /></th>
    </tr>
    <?php do { ?>
    <tr>
      <td><?php echo $row_rs_cateory['contentid']; ?></td>
      <td><a href="?page=content&amp;itemid=<?php echo $row_rs_cateory['contentid']; ?>"><?php echo $row_rs_cateory['ptitle']; ?></a></td>
      <td><?php echo $row_rs_cateory['categoryid']; ?></td>
      <td><?php echo $row_rs_cateory['datecreated']; ?></td>
      <td> <a href="?page=content&amp;cid=<?php echo $row_rs_cateory['contentid']; ?>">add Page </a></td>
      <td><?php echo $row_rs_cateory['ispublished']; ?>
        <input <?php if (!(strcmp($row_rs_cateory['ispublished'],1))) {echo "checked=\"checked\"";} ?> type="checkbox" name="delchk_<?php echo $row_rs_cateory['categoryid']; ?>" id="delchk_<?php echo $row_rs_cateory['categoryid']; ?>"  value="<?php echo $row_rs_cateory['categoryid']; ?>"/></td>
      </tr>
    <?php } while ($row_rs_cateory = mysql_fetch_assoc($rs_cateory)); ?>
  </table>
</form>

<?php
mysql_free_result($rs_cateory);
?>
